package userHeart

import (
	"gin-base/base"
	"gin-base/base/config"
	"gin-base/base/db"
	"time"
)

type UserHeart struct {
	UserId uint
	Max    float64
	Data   string
	base.Model
}

func (UserHeart) TableName() string {
	return config.Ini.String("mysql.table_prefix") + "user_heart"
}

func (this *UserHeart) Save() error {
	db := db.Open()
	defer db.Close()

	if db.NewRecord(this) {
		db.Create(&this)
	} else {
		this.UpdatedAt = time.Now()
		db.Save(&this)
	}
	return db.Error
}

func GetOneByUserId(User_id interface{}) (userHeart UserHeart) {
	db := db.Open()
	defer db.Close()

	db.Where("user_id = ?", User_id).First(&userHeart)

	return userHeart
}
